package com.effectiv.gooruda.rest.api.controller;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


import com.effectiv.gooruda.rest.api.operation.DataStorageOperations;


import lombok.extern.slf4j.Slf4j;


@Slf4j
@Controller
@RequestMapping("/api/data")
public class DataStorageController implements DataStorageOperations{
	
	@Autowired
	@Qualifier("dataStorageServiceImpl")
	private DataStorageOperations operations;
	
	
	@RequestMapping(value="{collection}" , method = RequestMethod.POST)
	public @ResponseBody String save(@PathVariable("collection") 
	 String collection, @RequestBody String data){
		log.info("Data = {}", data);
		String dbobj = operations.save(collection, data);
		log.info("dbobj = {}", dbobj);
		return dbobj;
	}

	
	
	
	@Override
	@RequestMapping(value="/findAll/{collection}/{query}" , method = RequestMethod.GET)
	public @ResponseBody  List<String> findAll(@PathVariable("collection")  String collection
			,@PathVariable("query")  String query) {
		return operations.findAll(collection, query);
	}
}
